package com.huilian.iotbox.admin.wap.controller;

import com.huilian.iotbox.admin.wap.service.RoleService;
import com.huilian.iotbox.data.common.ServerResponse;
import com.huilian.iotbox.data.dto.MemberDto;
import com.huilian.iotbox.data.dto.RoleDto;
import com.huilian.iotbox.data.enums.RoleEnum;
import com.huilian.iotbox.data.vo.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author LinYinDong
 * @date 2024/10/11 上午11:11
 */
@RestController
@RequestMapping("/api/role")
public class RoleController extends UserInfoController {
    @Autowired
    private RoleService roleService;

    @PostMapping("/findRoleList")
    public ServerResponse findRoleList(@RequestBody RoleDto roleDto, HttpServletRequest request) {
        UserInfo userInfo = super.getLoginUserInfo(request);
        if(userInfo.getRoleId().compareTo(RoleEnum.SUB_ACCOUNT.getRoleId())== 0){
            roleDto.setUserId(userInfo.getParentId());
        }else{
            roleDto.setUserId(userInfo.getId());
        }
        roleDto.setUserInfo(userInfo);
        return roleService.findRoleList(roleDto);
    }

    @GetMapping("/findRoleByUserIdList")
    public ServerResponse findRoleByUserIdList(HttpServletRequest request) {
        UserInfo userInfo = super.getLoginUserInfo(request);
        RoleDto roleDto = new RoleDto();
        if(userInfo.getRoleId().compareTo(RoleEnum.SUB_ACCOUNT.getRoleId())== 0){
            roleDto.setUserId(userInfo.getParentId());
        }else{
            roleDto.setUserId(userInfo.getId());
        }
        roleDto.setUserInfo(userInfo);
        return roleService.findRoleByUserIdList(roleDto);
    }
}
